package quotation.web.user.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import quotation.R.R;
import quotation.web.user.ddd.form.LoginForm;
import quotation.web.user.service.UserService;

import javax.validation.Valid;

/**
 * @author lyx
 * @date 2025/2/19
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户相关Api")
public class UserController {

    @Autowired
    private UserService userService;


    @PostMapping("/login")
    @ApiOperation("登录")
    public R login(@RequestBody @Valid LoginForm form) {

        String token = userService.login(form);

        return R.success("认证成功", token);
    }

    @GetMapping("/openIdLogin")
    @ApiOperation("微信openid登录")
    public R<String> openIdLogin(@RequestParam(value = "openId") String openId,
                                 @RequestParam(value = "inviteCode", required = false) String inviteCode) {

        String token = userService.openIdLogin(openId, inviteCode);

        return R.success("登陆成功",token);
    }


}
